package sharedspace;
import java.util.Calendar;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
/**
 *  class DateUtils get current date information
 *  dateFormat is String that represent element in timestamp 
 * 'YYYY' - year
 * 'MM' - month
 * 'dd' - day in month
 * 'HH' - hour
 * 'mm' - minute
 * 'ss' - second
 * @author Amir
 *
 */

public class DateUtils {

	public static String dateFormat = new String("yyyy-MM-dd HH:mm:ss");
	public static String year = new String("yyyy");
	public static String month = new String("MM");
	public static String day = new String("dd");
	public static String hour = new String("HH");
	public static String minutes = new String("mm");
	public static String second = new String("ss");
	/**
	 *
	 * @param dateFormat
	 * @return 
	 */
	public static String now(String dateFormat)
	{
		Calendar cal = Calendar.getInstance();
		SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
		return sdf.format(cal.getTime());

    }
	
	public static java.sql.Timestamp nowTimestamp(String dateFormat)
	{
		Calendar cal = Calendar.getInstance();
		SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
		java.util.Date date;
		try {
			date = sdf.parse(sdf.format(cal.getTime()));
			java.sql.Timestamp timestamp = new Timestamp(date.getTime());
			return timestamp;
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
		

    }
	
	public static int currentYear()
	{
		String year = DateUtils.now("YYYY");
		return Integer.parseInt(year);
	
	}
	
	public static int currentSemester()
	{
		String monthString = DateUtils.now("MM");
		int month = Integer.parseInt(monthString);
		switch (month)
		{
			case 1:
				return 1;
		
			case 2:
				return 1;
				
			case 3:
				return 2;
		
			case 4:
				return 2;
		
			case 5:
				return 2;
		
			case 6:
				return 2;
		
			case 7:
				return 2;
		
			case 8:
				return 2;
		
			case 9:
				return 1;
		
			case 10:
				return 1;
				
			case 11:
				return 1;
		
			case 12:
				return 1;
			
			default:
				return 1;
		
		}
	}

 
}
